package Euler266;

import java.math.*;
import java.util.*;
import ReusableCode.*;

public class PseudoSquareRoot {
	public static void main(String[] args) {
		BigInteger product = BigInteger.ONE;
		List<Integer> primes = PrimeFunctions.GetPrimes(190);
		
		Iterator<Integer> iter = primes.iterator();
		while(iter.hasNext())
		{
			BigInteger value = new BigInteger(String.valueOf(iter.next()));
			product = product.multiply(value);
		}
		
		BigInteger root = MathFunctions.getNthRoot(product, 2).getInteger();
		
		System.out.println("Number is: " + product + "\nSquare Root is: " + root);
		System.out.println(MathFunctions.getNthRoot(root, 2).getInteger());
		
		BigInteger lbound = MathFunctions.getNthRoot(root, 2).getInteger();
		for(BigInteger i = lbound; i.compareTo(BigInteger.ZERO)>0; i = i.subtract(BigInteger.ONE))
		{
			//System.out.println(i);
			if(i.mod(product).equals(BigInteger.ZERO))
			{
				System.out.println("Factor is: " + i);
				break;
			}
		}
	}
}